import { defineStore } from 'pinia'
import {
  getWarehouseDownList, shopExpresslist, getWarehouseAreaDownList, procurementAccountStatusDic, procurementPlatformDic, creatInventoryDic, searchInventoryDic, searchInventoryMoveOrderDic, productPurchaseStorageSearchWarehouseDic, productPurchaseProcessCreatePurchaseProcessDic, productPurchaseOrderSearchUserAdminDic, preSaleOrdergetOrderTypeList, productPurchaseStoragesearchWarehouseDicsw, shopExpressgetTbExpressList, getCompanyList, getOrderPlatformList, productReturnedStorageSearchDic, outSaleOrderGetCompanylist, warehouseShopgetOrderTypeList, warehouseShopGetOutOrderTypeList,
  productPurchaseReturnedListWarehouseDic,
  productGearPurchaseListWarehouseDic,
  sysConfigGetWarehouseAreaList,
  productGearList,
  productPurchaseReturnedListReturnedOrderStatusDic,
  productGearPurchaseStoragesearchWarehouseDic
} from '@/api/index'
import axios from 'axios'
import { ElMessage } from 'element-plus'
export const useAlertsStore = defineStore('alerts', {
  persist: {
    enabled: true
  },
  state: () => {
    return {
      routetPath: [],
      houseList: [],
      NewHouseList: [],
      NewshopExpresslistSelectArr: [],
      WarehouseTypeList: [],
      WarehouseTypeLists: [],
      WarehouseTypeListss: [],
      NewWarehouseTypeList: [],
      NewWarehouseTypeLists: [],
      NewWarehouseTypeListss: [],
      // 盘货用户
      InventoryUser: [],
      // 审核用户
      AuditUser: [],
      // 账号平台
      procurementPlatformDicTable: [],
      procurementAccountStatusDicTable: [],
      // 账号
      accountNumberTab: [],
      // 采购单账户信息字典
      productPurchaseOrderSearchUserAdminDicArr: [],
      godownHouseArr: [],
      productPurchaseProcessCreatePurchaseProcessDicArr: [],
      // 售前待审核订单类型
      preSaleOrdergetOrderTypeListArr: [],
      getOrderPlatformListArr: [],
      getCompanyListBtnArr: [],
      productReturnedStorageSearchDicArr: [],
      productPurchaseStoragesearchWarehouseDicswArr: [],
      outSaleOrderGetCompanylistTable: [],
      shopExpressgetTbExpressListTable: [],
      warehouseShopgetOrderTypeListTbale: [],
      warehouseShopgetOrderTypeListTbaleUnEvery: [],
      warehouseShopGetOutOrderTypeListTable: [],
      productPurchaseReturnedListWarehouseDicTable: [],
      topTypesForm: [],
      productGearPurchaseListWarehouseDicTable: [],
      sysConfigGetWarehouseAreaListTable: [],
      productGearPurchaseStoragesearchWarehouseDicTable: [],
      // 打印机websock
      socket: null
    }
  },
  actions: {
    // 仓库
    async wareHouseSelect () {
      const house = await getWarehouseDownList()
      const { data: { data } } = house
      this.houseList = data
      this.NewHouseList = [...data]
      this.houseList.shift()
    },
    // 店铺
    async shopExpresslistSelect (val) {
      const house = await shopExpresslist({ id: val })
      const { data: { data } } = house
      console.log('data')
      console.log(data)
      this.NewshopExpresslistSelectArr = [...data]
    },
    // 货区
    async getWarehouseAreaDownListApi (val) {
      console.log('val')
      console.log(val)
      const house = await getWarehouseAreaDownList(val)
      const { data: { data } } = house
      console.log('data')
      console.log(data)
      this.WarehouseTypeList = [...data]
      this.NewWarehouseTypeList = data
      this.NewWarehouseTypeList.shift()
    },
    // 货区
    async creatInventoryDicApi (val) {
      console.log('val')
      console.log(val)
      const house = await creatInventoryDic(val)
      const { data: { data } } = house
      this.WarehouseTypeLists = [...data]
      this.NewWarehouseTypeLists = data
      this.NewWarehouseTypeLists.shift()
    },
    // 货区
    async searchInventoryDicApi (val) {
      console.log('val')
      console.log(val)
      const house = await searchInventoryDic(val)
      const { data: { data } } = house
      console.log('data')
      console.log(data)
      this.WarehouseTypeListss = [...data.inventoryWarehouseDicList
      ]
      this.NewWarehouseTypeListss = data.inventoryWarehouseDicList

      this.NewWarehouseTypeListss.shift()
    },
    // 货区
    async searchInventoryMoveOrderDicApi (val) {
      console.log('val')
      console.log(val)
      const house = await searchInventoryMoveOrderDic(val)
      const { data: { data } } = house
      console.log(data)
      this.InventoryUser = [...data.operationUserDic]
      this.AuditUser = [...data.approveUserDic]
    },
    // 账号平台字典
    async procurementPlatformDicApi (val) {
      const house = await procurementPlatformDic(val)
      const { data: { data } } = house
      this.procurementPlatformDicTable = [...data.platformDicVOList]
    },
    // 退回上家出库单仓库
    async productPurchaseReturnedListWarehouseDicBtn (val) {
      const house = await productPurchaseReturnedListWarehouseDic(val)
      const { data: { data } } = house
      console.log('data-仓库')
      console.log(data)
      this.productPurchaseReturnedListWarehouseDicTable = [...data.warehouseDicList]
    },
    // 账号状态
    async procurementAccountStatusDicApi (val) {
      const house = await procurementAccountStatusDic(val)
      const { data: { data } } = house
      this.procurementAccountStatusDicTable = [...data.accountStatusDicVOList]
    },
    // 账号
    getAcc (valId) {
      axios.post(
        ' http://console.sc.kuaidi600.com/admin/admin/dropdown',
        {
          token: localStorage.getItem('system_token')
        }
      )
        .then((res) => {
          if (res.data.code === 200) {
            console.log(res)
            const { data: { data } } = res
            console.log('data')
            console.log(data)
            this.accountNumberTab = data
          } else {
            ElMessage({
              message: res.data.message,
              type: 'warning'
            })
          }
        })
        .catch((_err) => {
          ElMessage.error('请联系技术')
        })
    },
    // 采购入库仓库
    async godownHouse () {
      const { data: { data } } = await productPurchaseStorageSearchWarehouseDic()
      console.log(data)
      this.godownHouseArr = data.warehouseDics
    },
    // 采购单账户信息字典
    async productPurchaseOrderSearchUserAdminDicBtn () {
      const { data: { data } } = await productPurchaseOrderSearchUserAdminDic()
      console.log(data)
      this.productPurchaseOrderSearchUserAdminDicArr = data.userAdminDics
    },
    // 采购单账户信息字典
    async productPurchaseProcessCreatePurchaseProcessDicBtn () {
      const { data: { data } } = await productPurchaseProcessCreatePurchaseProcessDic()
      console.log(data)
      this.productPurchaseProcessCreatePurchaseProcessDicArr = data
    },
    // 售前待审核订单类型
    async preSaleOrdergetOrderTypeListBtn () {
      const { data: { data } } = await preSaleOrdergetOrderTypeList()
      console.log(data)
      this.preSaleOrdergetOrderTypeListArr = data
    },
    // 售前待审核订单来源平台
    async getOrderPlatformListBtn () {
      const { data: { data } } = await getOrderPlatformList()
      console.log(data)
      this.getOrderPlatformListArr = data
    },
    // 售前待审核获取货主
    async getCompanyListBtn () {
      const { data: { data } } = await getCompanyList()
      console.log(data)
      this.getCompanyListBtnArr = data
    },
    // 退货入库单信息字典
    async productReturnedStorageSearchDicBtn () {
      const { data: { data } } = await productReturnedStorageSearchDic()
      console.log(data)
      this.productReturnedStorageSearchDicArr = data.productTypeDics
    },
    // 获取采购入库仓库信息字典
    async productPurchaseStoragesearchWarehouseDicswBtn () {
      const { data: { data } } = await productPurchaseStoragesearchWarehouseDicsw()
      console.log('data')
      console.log(data)
      this.productPurchaseStoragesearchWarehouseDicswArr = data.warehouseDicList
    },
    // 获取采购入库仓库信息字典
    async outSaleOrderGetCompanylistBtn () {
      const { data: { data } } = await outSaleOrderGetCompanylist()
      console.log('data')
      console.log(data)
      this.outSaleOrderGetCompanylistTable = data
    },
    // 获取采购入库仓库信息字典
    async shopExpressgetTbExpressListbtn () {
      const { data: { data } } = await shopExpressgetTbExpressList()
      console.log('data')
      console.log(data)
      this.shopExpressgetTbExpressListTable = data
    },
    // 获取订单类型的列表
    async warehouseShopgetOrderTypeListBtn () {
      const { data: { data } } = await warehouseShopgetOrderTypeList()
      console.log('data')
      console.log(data)
      this.warehouseShopgetOrderTypeListTbale = [...data]
      this.warehouseShopgetOrderTypeListTbaleUnEvery = data
      this.warehouseShopgetOrderTypeListTbaleUnEvery.shift()
    },
    // 获取出单类型的列表
    async warehouseShopGetOutOrderTypeListBtn () {
      const { data: { data } } = await warehouseShopGetOutOrderTypeList()
      console.log('data')
      console.log(data)
      this.warehouseShopGetOutOrderTypeListTable = [...data]
    },
    // 档口下拉
    async productGearListBtn (val) {
      const { data: { data } } = await productGearList(val)
      console.log('data')
      console.log(data)
      this.productGearListTable = data
    },
    // 获取退回上家出库单仓库信息字典
    async productGearPurchaseListWarehouseDicBtn (val) {
      const { data: { data } } = await productGearPurchaseListWarehouseDic(val)
      console.log('data')
      console.log(data)
      this.productGearPurchaseListWarehouseDicTable = data.warehouseDicList
    },
    // 获取退回上家出库单仓库信息字典
    async productGearPurchaseStoragesearchWarehouseDicBtn (val) {
      const { data: { data } } = await productGearPurchaseStoragesearchWarehouseDic(val)
      console.log('data')
      console.log(data)
      this.productGearPurchaseStoragesearchWarehouseDicTable = data.warehouseDicList
    },
    // 获取库区下拉列表
    async sysConfigGetWarehouseAreaListBtn (val) {
      const { data: { data } } = await sysConfigGetWarehouseAreaList(val)
      console.log('data')
      console.log(data)
      this.sysConfigGetWarehouseAreaListTable = data
    },
    destroyed () {
      this.socket.close() // 离开路由之后断开websocket连接
    },
    // // 上家状态
    // topTypes () {
    //   axios.post('http://newyitao.sc.kuaidi600.com/aftersale/pcStatusGroup/pcStatusList', { token: localStorage.getItem('system_token') }
    //   ).then(res => {
    //     const { data: { data } } = res
    //     console.log('data-------top')
    //     console.log(data)
    //     this.topTypesForm = data
    //   })
    // }
    // 上家状态
    topTypes () {
      productPurchaseReturnedListReturnedOrderStatusDic().then(res => {
        const { data: { data } } = res
        console.log('data-------top')
        console.log(data)
        this.topTypesForm = data
      })
    }
  }
})
